package com.jinlejia.bbs.adapter.reply;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.graphics.Color;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jinlejia.bbs.R;
import com.jinlejia.bbs.bean.GambitBean;
import com.jinlejia.bbs.bean.base.BBSUserBean;
import com.jinlejia.bbs.bean.base.InformationBean;
import com.jinlejia.bbs.bean.base.SoundBean;
import com.jinlejia.bbs.bean.base.TopicBean;
import com.jinlejia.bbs.databinding.BbsAdapterMessageItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterReplyMessageItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterReplySoundItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterReplyTopicItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterSoundItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterTopicItemBinding;
import com.jinlejia.bbs.databinding.BbsMp3ViewLayoutBinding;
import com.jinlejia.bbs.logic.LikeFunLogic;
import com.jinlejia.bbs.ui.mine.others.BBSOtherUserMainActivity;
import com.jinlejia.bbs.ui.reply.BBSReplyDetailActivity;
import com.jinlejia.bbs.widget.mp3.AudioController;
import com.jinlejia.bbs.widget.mp3.Mp3AdapterHelper;
import com.jinlejia.erp.bean.SaveCookieBean;
import com.jinlejia.erp.utils.DbUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王进 on 2019/3/18.
 */

public class ReplyDetailAdapter extends Mp3AdapterHelper<ReplyBean> {
    private String ownPin;
    private LikeFunLogic likeFunLogic;
    public ReplyDetailAdapter(Context context,RecyclerView recyclerView,AudioController audioController) {
        super(context,audioController,recyclerView);
        likeFunLogic = new LikeFunLogic(context);
        ArrayList<SaveCookieBean> beans = DbUtil.getDB(context).single().query(SaveCookieBean.class);
        if (beans!=null && beans.size()>0){
            SaveCookieBean cookieBean = beans.get(0);
            ownPin = cookieBean.getPin();
        }
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder;

        switch (viewType) {
            case Inner.TYPE_TOPIC:
                viewHolder = new TopicViewHolder(inflater.inflate(R.layout.bbs_adapter_reply_topic_item, parent, false));
                break;
            case Inner.TYPE_MESSAGE:
                viewHolder = new MessageViewHolder(inflater.inflate(R.layout.bbs_adapter_reply_message_item,parent,false));
                break;
            case Inner.TYPE_SOUND:
                viewHolder = new SoundViewHolder(inflater.inflate(R.layout.bbs_adapter_reply_sound_item,parent,false));
                break;
            case Inner.TYPE_GAMBIT_MESSAGE:
                viewHolder = new GambitMessageViewHolder(inflater.inflate(R.layout.bbs_adapter_message_item, parent, false));
                break;
            case Inner.TYPE_GAMBIT_SOUND:
                viewHolder = new GambitSoundViewHolder(inflater.inflate(R.layout.bbs_adapter_sound_item, parent, false));
                break;
            case Inner.TYPE_GAMBIT_TOPIC:
                viewHolder = new GambitTopicViewHolder(inflater.inflate(R.layout.bbs_adapter_topic_item, parent, false));
                break;
            case Inner.TYPE_GAMBIT_TIP:
                viewHolder = new GambitTipViewHolder(inflater.inflate(R.layout.bbs_adapter_topic_tip_item, parent, false));
                break;
            default:
                throw new IllegalArgumentException("未知类型");
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof TopicViewHolder) {
            bindTopicViewHolder((TopicViewHolder) holder, position);
        }else if (holder instanceof MessageViewHolder){
            bindMessageViewHolder((MessageViewHolder) holder,position);
        }else if (holder instanceof SoundViewHolder){
            bindSoundViewHolder((SoundViewHolder) holder,position);
        }else if (holder instanceof GambitMessageViewHolder){
            bindGambitMessageViewHolder((GambitMessageViewHolder) holder,position);
        }else if (holder instanceof GambitSoundViewHolder){
            bindGambitSoundViewHolder((GambitSoundViewHolder) holder,position);
        }else if (holder instanceof GambitTopicViewHolder){
            bindGambitTopicViewHolder((GambitTopicViewHolder) holder,position);
        }
    }



    //region 话题内容
    private static class TopicViewHolder extends RecyclerView.ViewHolder {
        TopicViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    public interface DeleteListener{
        void onDelete(String topicCode,String answerCode);
    }

    private DeleteListener deleteListener;

    public void setDeleteListener(DeleteListener deleteListener) {
        this.deleteListener = deleteListener;
    }

    private void bindTopicViewHolder(TopicViewHolder holder, int position) {
        BbsAdapterReplyTopicItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        final TopicBean topic = mData.getTopic();
        binding.setTopic(topic);
        if (topic.isOwn()){
            binding.deleteTextView.setVisibility(View.VISIBLE);
        }else {
            binding.deleteTextView.setVisibility(View.GONE);
        }
        binding.deleteTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteListener.onDelete(topic.getTopicCode(),null);
            }
        });
    }
    //endregion

    //region 消息-文本 内容
    private static class MessageViewHolder extends RecyclerView.ViewHolder {
        MessageViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }
    public interface OnChangeAttentionListener{
        void onChangeAttention(InformationBean bean,int position);
    }
    private OnChangeAttentionListener listener;

    public void setListener(OnChangeAttentionListener listener) {
        this.listener = listener;
    }

    public interface OnClickUserInfoListener{
        void onClickUserInfo(BBSUserBean user,int position);
    }
    private OnClickUserInfoListener userInfoListener;

    public void setUserInfoListener(OnClickUserInfoListener userInfoListener) {
        this.userInfoListener = userInfoListener;
    }


    public interface OnReplyListener{
        void onReply(InformationBean bean,int position);
    }

    private OnReplyListener replyListener;

    public void setReplyListener(OnReplyListener replyListener) {
        this.replyListener = replyListener;
    }

    private void bindMessageViewHolder(MessageViewHolder holder, final int position){
        BbsAdapterReplyMessageItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        List<InformationBean> list = this.mData.getInformationList();
        final InformationBean bean = list.get(position - 1);
        BBSUserBean user = bean.getUser();
        if (bean.isOwnLike()) {
            binding.likeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.likeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }
        int type = user.getAttentionType();
        if (!TextUtils.isEmpty(ownPin) && TextUtils.equals(user.getUserPin(), ownPin)){
            binding.attentionStateTextView.setVisibility(View.GONE);
        }else
        //0:未关注 1：已关注 2：互相关注
        if (type==-1){
            binding.attentionStateTextView.setVisibility(View.GONE);
        }else if (type==0){
            binding.attentionStateTextView.setVisibility(View.VISIBLE);
            binding.attentionStateTextView.setText("关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#fccb00"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }else if (type==1){
            binding.attentionStateTextView.setVisibility(View.GONE);
            binding.attentionStateTextView.setText("已关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#999999"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }else if (type==2){
            binding.attentionStateTextView.setVisibility(View.GONE);
            binding.attentionStateTextView.setText("互相关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#fccb00"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }
        binding.attentionStateTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onChangeAttention(bean,position);
                }
            }
        });
        binding.userInfoLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userInfoListener!=null){
                    userInfoListener.onClickUserInfo(bean.getUser(),position);
                }
            }
        });
        binding.replyLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) { //评论
                if (replyListener!=null){
                    replyListener.onReply(bean,position);
                }
            }
        });
        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String answerCode = bean.getAnswerCode();
                likeFunLogic.execute(answerCode, new LikeFunLogic.LogicCallBack() {
                    @Override
                    public void onResult(boolean likeState) {
                        bean.setOwnLike(likeState);
                        if (likeState){
                            bean.setLikeCount(bean.getLikeCount()+1);
                        }else {
                            bean.setLikeCount(bean.getLikeCount()-1);
                        }
                        notifyItemChanged(position);
                    }
                });
            }
        });
        if (bean.isOwn()){
            binding.deleteTextView.setVisibility(View.VISIBLE);
        }else {
            binding.deleteTextView.setVisibility(View.GONE);
        }
        binding.deleteTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteListener.onDelete(null,bean.getAnswerCode());
            }
        });
        binding.contentTextView.setText(bean.getMessageContent());
        binding.setBean(bean);

    }
    //endregion

    //region
    private static class SoundViewHolder extends RecyclerView.ViewHolder{

        SoundViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindSoundViewHolder(SoundViewHolder holder,final int position){
        final BbsAdapterReplySoundItemBinding binding
                = DataBindingUtil.getBinding(holder.itemView);
        List<InformationBean> list = this.mData.getInformationList();
        final InformationBean bean = list.get(position - 1);
        binding.setBean(bean);
        if (bean.isOwnLike()) {
            binding.likeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.likeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }
        final SoundBean content = bean.getSoundContent();
        BbsMp3ViewLayoutBinding mp3Binding = binding.musicView.getBinding();
        initMp3View(mp3Binding,content,position);
        binding.replyLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) { //评论
                if (replyListener!=null){
                    replyListener.onReply(bean,position);
                }
            }
        });
        binding.userInfoLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userInfoListener!=null){
                    userInfoListener.onClickUserInfo(bean.getUser(),position);
                }
            }
        });
        BBSUserBean user = bean.getUser();
        if (bean.isOwnLike()) {
            binding.likeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.likeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.likeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }
        int type = user.getAttentionType();
        //0:未关注 1：已关注 2：互相关注
        if (type==-1){
            binding.attentionStateTextView.setVisibility(View.GONE);
        }else if (type==0){
            binding.attentionStateTextView.setVisibility(View.VISIBLE);
            binding.attentionStateTextView.setText("关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#fccb00"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }else if (type==1){
            binding.attentionStateTextView.setVisibility(View.GONE);
            binding.attentionStateTextView.setText("已关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#999999"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }else if (type==2){
            binding.attentionStateTextView.setVisibility(View.GONE);
            binding.attentionStateTextView.setText("互相关注");
            binding.attentionStateTextView.setTextColor(Color.parseColor("#fccb00"));
            binding.attentionStateTextView.setBackgroundResource(R.drawable.bbs_shape_button_checked);
        }

        binding.attentionStateTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onChangeAttention(bean,position);
                }
            }
        });
        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String answerCode = bean.getAnswerCode();
                likeFunLogic.execute(answerCode, new LikeFunLogic.LogicCallBack() {
                    @Override
                    public void onResult(boolean likeState) {
                        bean.setOwnLike(likeState);
                        if (likeState){
                            bean.setLikeCount(bean.getLikeCount()+1);
                        }else {
                            bean.setLikeCount(bean.getLikeCount()-1);
                        }
                        notifyItemChanged(position);
                    }
                });
            }
        });
        if (bean.isOwn()){
            binding.deleteTextView.setVisibility(View.VISIBLE);
        }else {
            binding.deleteTextView.setVisibility(View.GONE);
        }
        binding.deleteTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteListener.onDelete(null,bean.getAnswerCode());
            }
        });
    }

    @Override
    protected SoundBean getMp3SoundBean(int position) {
        List<InformationBean> list = this.mData.getInformationList();
        List<GambitBean> beanList = this.mData.getGambitBeanList();
        SoundBean oldSoundBean = null;
        if (list!=null && list.size()>position-1){
            if (position-1>=0){
                InformationBean bean = list.get(position - 1);
                oldSoundBean = bean.getSoundContent();
            }
        }else if (beanList!=null && beanList.size()>position-2){
            if (position-2>=0){
                GambitBean bean = beanList.get(position - 2);
                oldSoundBean = bean.getInfo().getSoundContent();
            }
        }
        return oldSoundBean;
    }

    @Override
    protected BbsMp3ViewLayoutBinding getMp3Binding(int position) {
        RecyclerView.ViewHolder holder = recyclerView.findViewHolderForLayoutPosition(position);
        BbsMp3ViewLayoutBinding mp3Binding = null;
        if (holder instanceof GambitSoundViewHolder){ //话题声音
            BbsAdapterSoundItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
            mp3Binding = binding.musicView.getBinding();
        }else if (holder instanceof SoundViewHolder){
            BbsAdapterReplySoundItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
            mp3Binding = binding.musicView.getBinding();
        }
        return mp3Binding;
    }

    //endregion
    @Override
    protected int getItemViewTypeZ(int position) {
        if (mData.getTopic()==null){
            return TYPE_EMPTY;
        }
        if (position == 0 && mData.getTopic() != null) {
            return Inner.TYPE_TOPIC;
        }
        List<GambitBean> gambitBeanList = mData.getGambitBeanList();
        if (position==1 && gambitBeanList!=null && !gambitBeanList.isEmpty()){
            return Inner.TYPE_GAMBIT_TIP;
        }
        List<InformationBean> list = mData.getInformationList();
        if (list!=null && !list.isEmpty()){
            InformationBean bean = list.get(position - 1);
            if (bean.getMessageContent()!=null){
                return Inner.TYPE_MESSAGE;
            }else {
                return Inner.TYPE_SOUND;
            }
        }
        if (gambitBeanList!=null && !gambitBeanList.isEmpty()){
            GambitBean bean = gambitBeanList.get(position - 2);
            InformationBean info = bean.getInfo();
            if (info==null){
                return Inner.TYPE_GAMBIT_TOPIC;
            }else
            if (info.getMessageContent() != null) {
                return Inner.TYPE_GAMBIT_MESSAGE;
            } else if (info.getSoundContent() != null) {
                return Inner.TYPE_GAMBIT_SOUND;
            } else {
                return Inner.TYPE_GAMBIT_TOPIC;
            }
        }
        return TYPE_EMPTY;
    }



    //region 文本消息行
    class GambitMessageViewHolder extends RecyclerView.ViewHolder {

        GambitMessageViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindGambitMessageViewHolder(GambitMessageViewHolder holder, final int position) {
        BbsAdapterMessageItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        List<GambitBean> list = mData.getGambitBeanList();
        int index = position - 2;
        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        final InformationBean information = bean.getInfo();
        List<BBSUserBean> likeList = information.getLikeUserList();
        if (likeList!=null){
            for (int i = 0; i < likeList.size(); i++) {
                switch (i){
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                        binding.setUser1(likeList.get(i));
                        break;
                    default:
                        break;
                }
            }
        }
        if (information.isOwnLike()) {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }

        View.OnClickListener toTopicListener =new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, BBSReplyDetailActivity.class);
                TopicBean topic = new TopicBean();
                topic.setTopicCode(bean.getTopic().getTopicCode());
                intent.putExtra("topic",topic);
                mContext.startActivity(intent);
            }
        };
        binding.topicClickView.setOnClickListener(toTopicListener);
        binding.titleTextView.setOnClickListener(toTopicListener);
        binding.userAnswerTextView.setOnClickListener(toTopicListener);

        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InformationBean info = bean.getInfo();
                likeFunLogic.execute(info.getAnswerCode(), new LikeFunLogic.LogicCallBack() {
                    @Override
                    public void onResult(boolean likeState) {
                        information.setOwnLike(likeState);
                        if (likeState){
                            information.setLikeCount(information.getLikeCount()+1);
                        }else {
                            information.setLikeCount(information.getLikeCount()-1);
                        }
                        notifyItemChanged(position);
                    }
                });
            }
        });
        binding.userAvatarImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BBSUserBean user = bean.getInfo().getUser();
                Intent intent = new Intent();
                intent.setClass(mContext, BBSOtherUserMainActivity.class);
                String pin = user.getUserPin();
                intent.putExtra("pin",pin);
                mContext.startActivity(intent);


            }
        });
    }
    //endregion

    //region 声音行
    class GambitSoundViewHolder extends RecyclerView.ViewHolder {
        GambitSoundViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }


    private void bindGambitSoundViewHolder(GambitSoundViewHolder holder, final int position) {
        final BbsAdapterSoundItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        List<GambitBean> list = mData.getGambitBeanList();
        int index = position - 2;
        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        List<BBSUserBean> userList = bean.getInfo().getLikeUserList();
        if (userList!=null){
            for (int i = 0; i < userList.size(); i++) {
                switch (i){
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                        binding.setUser1(userList.get(i));
                        break;
                    default:
                        break;
                }
            }
        }
        InformationBean info = bean.getInfo();
        final SoundBean content = info.getSoundContent();
        BbsMp3ViewLayoutBinding mp3Binding = binding.musicView.getBinding();
        initMp3View(mp3Binding,content,position);
        final InformationBean information = bean.getInfo();
        if (information.isOwnLike()) {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }

        View.OnClickListener toTopicListener =new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, BBSReplyDetailActivity.class);
                TopicBean topic = new TopicBean();
                topic.setTopicCode(bean.getTopic().getTopicCode());
                intent.putExtra("topic",topic);
                mContext.startActivity(intent);
            }
        };
        binding.topicClickView.setOnClickListener(toTopicListener);
        binding.titleTextView.setOnClickListener(toTopicListener);
        binding.userAnswerTextView.setOnClickListener(toTopicListener);

        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InformationBean info = bean.getInfo();
                likeFunLogic.execute(info.getAnswerCode(), new LikeFunLogic.LogicCallBack() {
                    @Override
                    public void onResult(boolean likeState) {
                        information.setOwnLike(likeState);
                        if (likeState){
                            information.setLikeCount(information.getLikeCount()+1);
                        }else {
                            information.setLikeCount(information.getLikeCount()-1);
                        }
                    }
                });
            }
        });
        binding.userAvatarImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BBSUserBean user = bean.getInfo().getUser();
                Intent intent = new Intent();
                intent.setClass(mContext, BBSOtherUserMainActivity.class);
                String pin = user.getUserPin();
                intent.putExtra("pin",pin);
                mContext.startActivity(intent);
            }
        });
    }
    //endregion

    //region 推荐话题标题
    private static class GambitTopicViewHolder extends RecyclerView.ViewHolder{
        GambitTopicViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindGambitTopicViewHolder(GambitTopicViewHolder holder,int position){
        BbsAdapterTopicItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        List<GambitBean> list = mData.getGambitBeanList();
        int index = position - 2;
        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        binding.titleTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("topic",bean.getTopic());
                intent.setClass(mContext, BBSReplyDetailActivity.class);
                mContext.startActivity(intent);
            }
        });
    }
    //endregion

    private static class GambitTipViewHolder  extends RecyclerView.ViewHolder{

        GambitTipViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }
    @Override
    public int getItemCount() {
        int emptyCount = 1;
        if (mData == null) {
            return emptyCount;
        }
        if (mData.getTopic() == null) {
            return emptyCount;
        }
        if ((mData.getInformationList() == null || mData.getInformationList().isEmpty())
                && (mData.getGambitBeanList() == null || mData.getGambitBeanList().isEmpty())) {
            return 1;
        }
        if (mData.getInformationList() != null &&! mData.getInformationList().isEmpty()){
            return 1 + mData.getInformationList().size();
        }
        if (mData.getGambitBeanList() != null &&! mData.getGambitBeanList().isEmpty()){
            return 2 + mData.getGambitBeanList().size();
        }
        return emptyCount;
    }



    private static final class Inner {
        final static int TYPE_TOPIC = 1;
        final static int TYPE_MESSAGE = 2;
        final static int TYPE_SOUND = 3;

        final static int TYPE_GAMBIT_MESSAGE = 4;
        final static int TYPE_GAMBIT_SOUND = 5;
        final static int TYPE_GAMBIT_TOPIC = 6;

        final static int TYPE_GAMBIT_TIP = 7;

        final static int TYPE_DELETED = 8;
    }
}
